clear all;
close all;
clc
% Subjects = {'A63','A64','A68','A69','A70','A72','A73','A74','A75','A76','A77','A78','A79','A80','A81','A82'};
Subjects = {'A81','A82'};
% Subjects = {'A72'}
% hiddenlayers = 5;
% 72
% Channels = 1:31;
fs=500;
% Q = 100;
% fs_low = fs/Q;
dt = 1/fs;
f_Conditions_EMG_EEG_up
fingers = 'abcde';
% pcolor = 'kbr';
% Pre = 0; % on
% dur = 3.5; % off
% tsig_ori=Pre+dt:dt:dur;
% tsig_plot=Pre+dt*Q:dt*Q:dur;
% NN = length(tsig_ori);
plot_triggers = 0;
for isub = 1:length(Subjects)
    Sub = Subjects{isub}
%     finger_names = {'Thumb';'Index';'Middle';'Ring';'Pinky'};
    eval(['condall=' Sub '_all;']);
%     outcor = f_heatmap_subplot(4,4);
%     for ifinger = 1:5
%         ERP{ifinger}= [];
%     end

    for isession = 1:N_column:length(condall)
%     for isession = 1:N_column:20*2
        chunkline = {condall{isession:isession+N_column-1}};
        if mod(isession,10)==1
            chunkline
        end
        finger = chunkline{1}(end);
        ifinger = find(fingers==finger);
        fname = ['EEG_data\' chunkline{2} ];
        sample1 = 1;
        sample2= 10;
        eeg = read_eep_cnt(fname, sample1, sample2);
        sample2 = eeg.nsample;
        eeg = read_eep_cnt(fname, sample1, sample2);

        % eeg = read_eep_cnt('A63_Olivia_2021-09-20_14-22-07.cnt', 0, 13);


        eval(['load ' fname(1:end-4) '_P']);
%         Nchannel = eeg.nchan;
        % Nchannel=31;
        tsig_long = eeg.time./1000;
        % tsig_long=dt:dt:dt*length(new_data)
        % ***** triggers & PRHs (period histograms)
        % first, get the behavioral file:
        outTT = f_process_trigger(eeg,chunkline{3},plot_triggers,20);
        newTR_time = outTT.newTR_time;
        eval(['save ' fname(1:end-4) '_P newTR_time new_data tsig_long']);
        pause(0.1)
    end
end